function rander(data){
    $('.row').remove();
    data.forEach(item => {
        let html = 
        `
        <tr class="row">
        <td>${item.id}</td>
        <td>${item.name}</td>
        <td>${item.price}</td>
        <td>${item.stock}</td>
        <td><input type="button" value="编辑" onclick="endit(${item.id})"></td>
        <td><input type="button" value="删除" onclick="del(${item.id})"></td>
    </tr>
        
        `
        $('#data_table').append(html);
    });
}


$(function (){
    getproduce().then(data=>{

        rander(data)
    })
})


function del(id){
    delproduce(id).then(data=>{
        rander(data)
    })
}

function endit(id){
    window.location.href = `addOrEndit.html?${id}`
}
function add(){
    window.location.href = `addOrEndit.html`
}


function query(){
    let keyword = $('[name=keyword]').val();
    console.log(keyword);
    if(keyword.length!=0){
        getproduce(keyword).then(data=>{
           
            rander(data)
        })
    }else{
        alert('查找的信息不能为空');
    }
}

